package com.bingbing.bingbingmall.member.web;

import com.alibaba.fastjson.JSON;
import com.bingbing.common.utils.R;
import com.bingbing.bingbingmall.member.feign.OrderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
public class MemberWebController {

    @Autowired
    OrderFeignService orderFeignService;

    /**
     * 订单分页查询
     * @param pageNum
     * @param model
     * @return
     */
    @GetMapping("/memberOrder.html")
    public String memberOrderPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "message", required = false) Integer message,Model model){

        //查出当前登录的用户的所有订单列表数据
        Map<String,Object> page =new HashMap<>();
        page.put("page",pageNum.toString());
        R r = orderFeignService.listWithItem(page);
        System.out.println(JSON.toJSONString(r));
        model.addAttribute("orders",r);
        if (message != null && message == 0) {
            model.addAttribute("msg","该订单已经被支付！");
        }
        return "orderList";
    }

    @ResponseBody
    @GetMapping("/toCancelOrder/{orderSn}")
    public String toCancelOrder(@PathVariable("orderSn") String orderSn){
        String CancelMsg = orderFeignService.cancelOrder(orderSn);
        return CancelMsg;
    }

    @ResponseBody
    @GetMapping("/toAffirmOrder/{orderSn}")
    public String toAffirmOrderOrder(@PathVariable("orderSn") String orderSn){
        String CancelMsg = orderFeignService.affirmOrder(orderSn);
        return CancelMsg;
    }

    @ResponseBody
    @GetMapping("/toApplyOrder/{orderSn}")
    public String toApplyOrder(@PathVariable("orderSn") String orderSn){
        String CancelMsg = orderFeignService.applyOrder(orderSn);
        return CancelMsg;
    }

    @ResponseBody
    @GetMapping("/toAccomplishOrder/{orderSn}")
    public String toAccomplishOrder(@PathVariable("orderSn") String orderSn){
        String CancelMsg = orderFeignService.accomplishOrder(orderSn);
        return CancelMsg;
    }
}
